package ipebg.mzk.facade.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.springframework.security.core.GrantedAuthority;

/**
 * 
 * @author H2601981 2015/10/10
 *
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "MS_ROLE")
public class MsAdminRole implements Serializable, GrantedAuthority {
	@Id
	@GenericGenerator(name = "hibernate-uuid", strategy = "uuid")
	@GeneratedValue(generator = "hibernate-uuid")
	@Column(name = "ROLEID")
	private String roleId;
	@Column(name = "ROLENAME")
	private String roleName;
	@Column(name = "ROLECODE")
	private String roleCode;
	@Column(name = "CREATEDTIME")
	private Date createdTime;
	@Column(name = "EDITTIME")
	private Date editTime;
	@Column(name = "DESCRIPTION")
	private String description;
	
	//多对多
	
	//@ManyToMany(targetEntity=MsAdminUser.class,mappedBy="roleList")
	//@ManyToMany(targetEntity=MsAdminUser.class,fetch=FetchType.EAGER,mappedBy="roleList")
	//public List<MsAdminUser> userList = new ArrayList<MsAdminUser>();	
	@Transient
	public List<MsAdminFunction> functionLists=new ArrayList<MsAdminFunction>();
		
	public static final MsAdminFunction[] EMPTY_FUNCTION = new MsAdminFunction[0];
	public static final MsAdminUser[] EMPTY_USER = new MsAdminUser[0];
		
	public MsAdminRole(){
		//this.userList = new ArrayList<MsAdminUser>();
		this.functionLists = new ArrayList<MsAdminFunction>();		
	}
		
	public MsAdminFunction[] getGrantedPrivilege(){
		if (this.functionLists == null || this.functionLists.size() <=0)
			return EMPTY_FUNCTION;
		MsAdminFunction[] grantedPrivileges = new MsAdminFunction[this.functionLists.size()];
		this.functionLists.toArray(grantedPrivileges);
		return grantedPrivileges;
	}

	public String getRoleId() {
		return roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getRoleCode() {
		return roleCode;
	}

	public void setRoleCode(String roleCode) {
		this.roleCode = roleCode;
	}

	public Date getCreatedTime() {
		return createdTime;
	}

	public void setCreatedTime(Date createdTime) {
		this.createdTime = createdTime;
	}

	public Date getEditTime() {
		return editTime;
	}

	public void setEditTime(Date editTime) {
		this.editTime = editTime;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}




	public List<MsAdminFunction> getFunctionLists() {
		return functionLists;
	}

	public void setFunctionLists(List<MsAdminFunction> functionLists) {
		this.functionLists = functionLists;
	}

	@Override
	public String getAuthority() {
		// TODO Auto-generated method stub
		return this.roleCode;
	}
}
